<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ page import="com.simhash.Main" %>

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link type="text/css" rel="stylesheet" href="style.css">
		<title>文本相似度检测系统</title>
	</head>
	<body>
		<%
			request.setCharacterEncoding("utf-8");//防止中文乱码
			String text_a ="";
        	String text_b = "";
        	int s = 0;
        	String outs = "";
        	text_a = request.getParameter("text1");
        	text_b = request.getParameter("text2");
        	Main main = new Main();
        	if(text_a != null && !text_a.equals("") && text_b != null && !text_b.equals("")) {
        		main.setText_a(text_a);//文本1
    			main.setText_b(text_b);//文本2
    			s = main.getHmjl();
    			outs = "经检测，上述两个文本的海明距离为："+s+"（共128位），相似度为："+((128-s)*100/128)+"%";
    			//if(s >= 40)
    				//outs = "经检测，上述两个文本的相似度为：八竿子打不着";
        	} else {
        		outs = "经检测，本次检测无效！";
        	}
			if((text_a == null || text_b == null) || (text_a.equals("") && text_b.equals(""))) {
				text_a = "";
				text_b = "";
				outs = "&nbsp;";
			}
    	%>
    
		<h1 id="head">文 本 相 似 度 检 测 系 统</h1>
		<hr>
	
	
		<form name="form" action="" method="post">
        	<div id="table">
        		<div class="tableRow">
        			<p class="tableCell">请在下方文本框中输入文本（1）</p>
        			<p class="tableCell">请在下方文本框中输入文本（2）</p>
        		</div>
        		<div class="tableRow">
        			<div class="tableCell">
        				<textarea name="text1"><%=text_a %></textarea>
        			</div>
        			<div class="tableCell">
        				<textarea name="text2"><%=text_b %></textarea>
        			</div>
        		</div>
        	</div>
        	<br>
        	<div class="jiance">
        		<input type="submit" name="submit" value="检&nbsp;&nbsp;测"/>
        	</div>
        	<br>
        	<div class="jiance">
        		<p><%=outs %></p>
        	</div>
    	</form>
    
    
    	<div id="foot">
    		<hr>
    		&copy; 2012, 文本相似度检测系统
    		<br>
    		昆明理工大学&nbsp;&nbsp;信息与自动化学院&nbsp;&nbsp;祁俊辉&nbsp;&nbsp;版权所有
    	</div>
	</body>
</html>